//var editRow = undefined; //定义全局变量：当前编辑的行
var editRow1 = undefined;
var editRow2 = undefined;
var editRow3 = undefined;
var datagrid1; //定义全局变量datagrid
var datagrid2;
var datagrid3;
var selectUserId = "";//人员编辑id
$(function () {
    //加载部门树
    queryDepartmentTree();
    //  alert(CONSTANT.DictionaryTypeDefConstants.HD_REASON);
    //加载数据字典下拉列表
    queryDictionaryList("accidentLevelId", CONSTANT.DictionaryTypeDefConstants.ACCIDENT_LEVEL);//事故等级
    queryDictionaryList("accidentTypeId", CONSTANT.DictionaryTypeDefConstants.ACCIDENT_TYPE);//事故类别
    //火灾或爆炸级别
    queryDictionaryList("fireOrExplosionLevelId", CONSTANT.DictionaryTypeDefConstants.EXPLODE_LEVEL);
    //泄漏级别下拉列表
    queryDictionaryList("leakLevelId", CONSTANT.DictionaryTypeDefConstants.LEAK_LEVEL);
    //作业环节
    queryDictionaryList("jobStepId", CONSTANT.DictionaryTypeDefConstants.WORK_LINK);
    //作业活动
    queryDictionaryList("jobActivityId", CONSTANT.DictionaryTypeDefConstants.ACTIVITY);
    //加载直接原因类型
    queryDirectReasonTypeList("directReasonTypeId", CONSTANT.DictionaryTypeDefConstants.DIRECT_REASON_TYPE);
    //加载间接原因类型
    queryDictionaryList("indirectReasonTypeId", CONSTANT.DictionaryTypeDefConstants.INDIRECT_CAUSE);
    //事故性质
    queryDictionaryList("accidentNatureId", CONSTANT.DictionaryTypeDefConstants.ACCIDENT_CHARACTER);
    //不安全行为
    queryDictionaryList("unsafeActId", CONSTANT.DictionaryTypeDefConstants.UNSAFE_ACT);
    //不安全状态
    queryDictionaryList("unsafeStateId", CONSTANT.DictionaryTypeDefConstants.UNSAFE_STATE);
    datagrid1 = $("#casualtiesList").datagrid({
        url: ROOT_PATH + '/accidentEvent/accidentReport/queryCasualtiesList.shtml', //请求的数据源
        queryParams: {
            accidentReportId: accidentReportId,
        },
        iconCls: 'icon-save', //图标
        rownumbers: true,
        singleSelect: true,
        fit: true, //datagrid自适应宽度
        fitColumns: true, //列自适应宽度
        striped: true, //行背景交换
        nowap: true, //列内容多时自动折至第二行
        //border: false,
        toolbar: '#casualtiesTb',
        idField: 'id', //主键
        columns: [[//显示的列
            {field: 'ckId', width: 100, checkbox: true},
            {
                field: 'personalTypeName', width: 100, hidden: true, editor: {
                type: 'textbox', options: {}
            }
            },
            {
                field: 'personalTypeId', title: '人员分类', width: 200, editor: {
                type: 'combobox',
                options: {
                    required: true,
                    valueField: 'value',
                    textField: 'text'
                }
            },
                formatter: function (value, row, index) {
                    return row.personalTypeName;
                }
            },
            {
                field: 'userId', width: 100, hidden: true, editor: {
                type: 'textbox', options: {}
            }
            },
            {
                field: 'userName', title: '姓名', width: 200,
                editor: {
                    type: 'textbox', options: {
                        editable: false,
                        required: 'true',
                        icons: [{
                            iconCls: 'icon-add',
                            handler: function (e) {
                                //选择人员信息
                                selectUserInfo_datagrid("1");
                            }
                        }]

                    }
                }
            },
            {
                field: 'sex', title: '性别', width: 150, editor: {
                type: 'combobox',
                options: {
                    panelHeight: 50,
                    required: true,
                    valueField: 'value',
                    textField: 'text',
                    editable: false,
                    data: [{
                        value: '0',
                        text: '男'
                    }, {
                        value: '1',
                        text: '女'
                    }]
                }
            },
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return '女';
                    } else {
                        return '男';
                    }
                }
            },
            {
                field: 'age', title: '年龄', width: 200,
                editor: {
                    type: 'numberspinner', options: {
                        required: true,
                        value: 0,
                        min: 0
                    }
                }
            },
            {
                field: 'workType', title: '工种', width: 200,
                editor: {
                    type: 'textbox', options: {
                        multiline: true
                    }
                }
            },
            {
                field: 'workAge', title: '本工种工龄', width: 200, editor: {
                type: 'numberspinner', options: {
                    required: true,
                    min: 0
                }
            }
            },
            {
                field: 'educationName', width: 100, hidden: true, editor: {
                type: 'textbox', options: {}
            }
            },
            {
                field: 'educationId', title: '文化程度', width: 200, editor: {
                type: 'combobox',
                options: {
                    required: true,
                    valueField: 'value',
                    textField: 'text'
                }
            },
                formatter: function (value, row, index) {
                    return row.educationName;
                }
            },
            {
                field: 'directDamageReasonName', width: 100, hidden: true, editor: {
                type: 'textbox', options: {}
            }
            },
            {
                field: 'directDamageReasonId', title: '直接伤害原因', width: 200, editor: {
                type: 'combobox',
                options: {
                    required: true,
                    valueField: 'value',
                    textField: 'text'
                }
            },
                formatter: function (value, row, index) {
                    return row.directDamageReasonName;
                }
            },
            {
                field: 'damagePartName', width: 100, hidden: true, editor: {
                type: 'textbox', options: {}
            }
            },
            {
                field: 'damagePartId', title: '伤害部位', width: 200, editor: {
                type: 'combobox',
                options: {
                    required: true,
                    valueField: 'value',
                    textField: 'text'
                }
            },
                formatter: function (value, row, index) {
                    return row.damagePartName;
                }
            },
            {
                field: 'severityName', width: 100, hidden: true, editor: {
                type: 'textbox', options: {}
            }
            },
            {
                field: 'severityLevel', width: 100, hidden: true, editor: {
                type: 'textbox', options: {}
            }
            },
            {
                field: 'severityId', title: '严重程度', width: 200, editor: {
                type: 'combobox',
                options: {
                    required: true,
                    valueField: 'value',
                    textField: 'text'
                }
            },
                formatter: function (value, row, index) {
                    return row.severityName;
                }
            }

        ]],
        onAfterEdit: function (rowIndex, rowData, changes) {
            //endEdit该方法触发此事件
            // console.info(rowData);
            // var rows= datagrid.datagrid("getChanges");
            //console.log(rows);
            editRow1 = undefined;
        },
        onDblClickRow: function (rowIndex, rowData) {
            //双击开启编辑行
            editTableRow1();
            /*if (editRow1 != undefined) {
             datagrid1.datagrid("endEdit", editRow1);
             }
             if (editRow1 == undefined) {
             datagrid1.datagrid("beginEdit", rowIndex);
             editRow1 = rowIndex;
             }*/
        },
        onEndEdit: function (index, row, changes) {
            //保存行数据时同时判断各个严重程度的人数
            var rows = datagrid1.datagrid("getData").rows;
            var dieNum = 0;
            var seriousInjuryNum = 0;
            var slightInjuryNum = 0;
            for (i = 0; i < rows.length; i++) {
                if (rows[i].severityLevel == 1) {
                    dieNum++;
                }
                if (rows[i].severityLevel == 2) {
                    seriousInjuryNum++;
                }
                if (rows[i].severityLevel == 3) {
                    slightInjuryNum++;
                }
            }
            $("#dieNum").textbox("setValue", dieNum);
            $("#seriousInjuryNum").textbox("setValue", seriousInjuryNum);
            $("#slightInjuryNum").textbox("setValue", slightInjuryNum);
        }
    });
    datagrid2 = $("#handlingSuggestionList").datagrid({
        url: ROOT_PATH + '/accidentEvent/accidentReport/queryHandlingSuggestionList.shtml', //请求的数据源
        queryParams: {
            accidentReportId: accidentReportId,
        },
        iconCls: 'icon-save', //图标
        rownumbers: true,
        singleSelect: true,
        fit: true, //datagrid自适应宽度
        fitColumns: true, //列自适应宽度
        striped: true, //行背景交换
        nowap: true, //列内容多时自动折至第二行
        //border: false,
        toolbar: '#manageSuggestionTb',
        idField: 'id', //主键
        columns: [[//显示的列
            {field: 'ckId', width: 100, checkbox: true},
            {
                field: 'dutyTypeName', width: 100, hidden: true, editor: {
                type: 'textbox', options: {}
            }
            },
            {
                field: 'dutyTypeId', title: '责任类型', width: 200,
                editor: {
                    type: 'combobox', options: {
                        required: true,
                        valueField: 'value',
                        textField: 'text'
                    }
                }
                , formatter: function (value, row, index) {
                return row.dutyTypeName;
            }
            },
            {
                field: 'personalTypeName', width: 100, hidden: true, editor: {
                type: 'textbox', options: {}
            }
            },
            {
                field: 'personalTypeId', title: '人员分类', width: 200, editor: {
                type: 'combobox',
                options: {
                    required: true,
                    valueField: 'value',
                    textField: 'text'
                }
            },
                formatter: function (value, row, index) {
                    return row.personalTypeName;
                }
            },
            {
                field: 'userId', width: 100, hidden: true, editor: {
                type: 'textbox', options: {}
            }
            },
            {
                field: 'userName', title: '姓名', width: 200,
                editor: {
                    type: 'textbox', options: {
                        editable: false,
                        required: 'true',
                        icons: [{
                            iconCls: 'icon-add',
                            handler: function (e) {
                                //选择人员信息
                                selectUserInfo_datagrid("2");
                            }
                        }]

                    }
                }
            },
            {
                field: 'executiveLevel', title: '行政级别', width: 100, editor: {
                type: 'textbox',
                options: {
                    //required:true,
                    readonly: true
                }
            }
            },
            {
                field: 'handlingSuggestion', title: '处理意见', width: 200, editor: {
                type: 'textbox',
                options: {
                    multiline: true,
                    required: true,
                    valueField: 'value',
                    textField: 'text'
                }
            }
            }
        ]],
        onAfterEdit: function (rowIndex, rowData, changes) {
            //endEdit该方法触发此事件
            // console.info(rowData);
            // var rows= datagrid.datagrid("getChanges");
            //console.log(rows);
            editRow2 = undefined;
        },
        onDblClickRow: function (rowIndex, rowData) {
            editTableRow2();
        }
    });
    datagrid3 = $("#precautionList").datagrid({
        url: ROOT_PATH + '/accidentEvent/accidentReport/querPrecautionList.shtml', //请求的数据源
        queryParams: {
            accidentReportId: accidentReportId,
        },
        iconCls: 'icon-save', //图标
        rownumbers: true,
        singleSelect: true,
        fit: true, //datagrid自适应宽度
        fitColumns: true, //列自适应宽度
        striped: true, //行背景交换
        nowap: true, //列内容多时自动折至第二行
        //border: false,
        toolbar: '#precautionTb',
        idField: 'id', //主键
        columns: [[//显示的列
            {field: 'ckId', width: 100, checkbox: true},
            //{field:'dutyUserId',width:100,hidden:true},
            {
                field: 'precautionContent', title: '措施内容', width: 200,
                editor: {
                    type: 'textbox', options: {
                        multiline: true
                    }
                }
            },
            {
                field: 'dutyUserId', width: 100, hidden: true, editor: {
                type: 'textbox', options: {}
            }
            },
            {
                field: 'dutyUserName', title: '责任人', width: 200,
                editor: {
                    type: 'textbox', options: {
                        editable: false,
                        required: 'true',
                        icons: [{
                            iconCls: 'icon-add',
                            handler: function (e) {
                                //选择人员信息
                                selectDutyUserInfo_datagrid("3");
                            }
                        }]

                    }
                }
            },
            {
                field: 'planFinishTime', title: '计划完成日期', width: 200,
                editor: {
                    type: 'datebox', options: {
                        required: true,
                        editable: false
                    }
                }
            },
            {
                field: 'verifyUserId', width: 100, hidden: true, editor: {
                type: 'textbox', options: {}
            }
            },
            {
                field: 'verifyUserName', title: '验证人', width: 200,
                editor: {
                    type: 'textbox', options: {
                        editable: false,
                        required: 'true',
                        icons: [{
                            iconCls: 'icon-add',
                            handler: function (e) {
                                selectVerifyUserInfo_datagrid("3");
                            }
                        }]

                    }
                }
            },
            {field: 'verifySuggestion', title: '验证意见', width: 300},
            {field: 'verifyDate', title: '验证日期', width: 200}
        ]],
        onAfterEdit: function (rowIndex, rowData, changes) {
            //endEdit该方法触发此事件
            // console.info(rowData);
            // var rows= datagrid.datagrid("getChanges");
            //console.log(rows);
            editRow3 = undefined;
        },
        onDblClickRow: function (rowIndex, rowData) {
            //双击开启编辑行
            if (editRow3 != undefined) {
                datagrid3.datagrid("endEdit", editRow3);
            }
            if (editRow3 == undefined) {
                datagrid3.datagrid("beginEdit", rowIndex);
                editRow3 = rowIndex;
            }
        }
    });
    /**
     * 保存按钮事件
     */
    $('#btn_save').on("click", function () {
        //var ret = $("#hdRegisterForm").form('validate');
        //表单验证
        if (/*$("#infoForm").form('validate')*/ true) {
            layer.confirm("确定保存？", {btn: ['确定', '取消']}, function () {
                var layerIndex = parent.layer.getFrameIndex(window.name); //获取窗口索引
                //序列化表单数据
                var data = $("#infoForm").serializeArray();
                //获取行编辑数据
                data.push({name: 'casualtiesList', value: getDetailData1()});
                data.push({name: 'handlingSuggestionList', value: getDetailData2()});
                data.push({name: 'precautionList', value: getDetailData3()});
                $.ajax({
                    url: ROOT_PATH + '/accidentEvent/accidentReport/editAccidentReportInfo.shtml',//提交地址
                    data: data,//将表单数据序列化
                    type: "POST",
                    dataType: "json",
                    success: function (result) {
                        if (result.success) {
                            layer.msg(result.message, {time: 1000, icon: 1}, function () {
                                WindowManager.closeLayer({
                                    returnValue: ""
                                });
                            });
                        } else {
                            layer.msg(result.message, {time: 1000, icon: 1}, function () {
                                //parent.layer.close(layerIndex);
                            });
                        }
                    }
                });
            });
        } else {
            layer.msg("请按规则填写信息!", {time: 1000, icon: 2});
        }

    });
    /**
     * 绑定人员选择事件
     */

    $("#reportUser").textbox({
        iconWidth: 15,
        icons: [{
            iconCls: 'icon-add',
            handler: function (e) {
                selectUserId = "reportUser";
                add_userInfo_func();
            }
        }]
    });
    $("#safetyDeptDutyUser").textbox({
        iconWidth: 15,
        icons: [{
            iconCls: 'icon-add',
            handler: function (e) {
                selectUserId = "safetyDeptDutyUser";
                add_userInfo_func();
            }
        }]
    });
    $("#chargeLeader").textbox({
        iconWidth: 15,
        icons: [{
            iconCls: 'icon-add',
            handler: function (e) {
                selectUserId = "chargeLeader";
                add_userInfo_func();
            }
        }]
    });

    /**
     * 提交按钮事件
     */
    $('#btn_submit').on("click", function () {
        //var ret = $("#hdRegisterForm").form('validate');
        //表单验证
        if ($("#infoForm").form('validate')) {
            layer.confirm("确定保存并提交审批？", {btn: ['确定', '取消']}, function () {
                var layerIndex = parent.layer.getFrameIndex(window.name); //获取窗口索引
                //序列化表单数据
                var data = $("#infoForm").serializeArray();
                //获取行编辑数据
                data.push({name: 'casualtiesList', value: getDetailData1()});
                data.push({name: 'handlingSuggestionList', value: getDetailData2()});
                data.push({name: 'precautionList', value: getDetailData3()});
                /***
                 * 选择处理人
                 */
                WindowManager.openLayer({
                    type: 2,
                    title: '选择下一环节处理人',
                    area: ['370px', '180px'],
                    content: ROOT_PATH + '/workflow/flowManagement/toFlowNextUserSelectPage.shtml',
                    data: {id: 'ff', name: '我是名称'},
                    callBack: function (result) {//窗口关闭后的回调函数
                        //得到选择的人员
                        if (result == null || result === "") {
                            layer.alert("请选择处理人!");
                            return false;
                        }
                        data.push({name: 'nextUserId', value: result});
                        $.ajax({
                            url: ROOT_PATH + '/accidentEvent/accidentReport/editAndSubmit.shtml',//提交地址
                            data: data,//将表单数据序列化
                            type: "POST",
                            dataType: "json",
                            success: function (result) {
                                if (result.success) {
                                    layer.msg(result.message, {time: 1000, icon: 1}, function () {
                                        WindowManager.closeLayer({
                                            returnValue: ""
                                        });
                                    });
                                } else {
                                    layer.msg(result.message, {time: 1000, icon: 1}, function () {
                                        //parent.layer.close(layerIndex);
                                    });
                                }
                            }
                        });

                    }
                });


            });
        } else {
            layer.msg("请按规则填写信息!", {time: 1000, icon: 2});
        }

    });
    /**
     * 选择风险区域
     */
    /* $("#site").textbox({
     iconWidth: 15,
     icons: [{
     iconCls: 'icon-add',
     handler: function(e){
     selectUserId ="site";
     add_riskRegionInfo_func();
     }
     }]
     });*/
    /**
     * 绑定选择事故信息弹出框
     */
    $("#accident").textbox({
        iconWidth: 15,
        icons: [{
            iconCls: 'icon-add',
            handler: function (e) {
                selectUserId = "accident";
                add_accident_func();
            }
        }]
    });

    /**
     * 绑定作业项目选择事件
     */
    /*$("#project").textbox({
     iconWidth: 15,
     height: 30,
     icons: [{
     iconCls: 'icon-add',
     handler: function(e){
     //selectUserId ="recogniseUsers";
     add_jobProject_func();
     }
     }]
     });*/
    /**
     * 选择承包商
     */
    $("#contractor").textbox({
        iconWidth: 15,
        height: 30,
        icons: [{
            iconCls: 'icon-add',
            handler: function (e) {
                WindowManager.openLayer({
                    type: 2,
                    title: '选择承包商',
                    area: ['700px', '400px'],
                    content: ROOT_PATH + '/contractor/contractorAudit/auditedList.shtml',
                    callBack: function (data) {
                        console.log(data);
                        $("#contractorId").val(data[0].id);
                        $("#contractor").textbox("setValue", data[0].contractorName);
                    }
                });
            }
        }]
    });
    /**
     * 是否承包商切换
     */
    $("#isContractor").combobox({
        onSelect: function (record) {
            var val = record.value;
            if (val == 1) {
                $("#contractorDiv").show();
                $("#contractor").textbox("enableValidation");
            } else {
                $("#contractorDiv").hide();
                $("#contractor").textbox("clear");
                $("#contractor").textbox("disableValidation");
                $("#contractorId").val('');
            }
        }
        /*,
         onChange:function(newVal,oldVal){
         if(newVal!=oldVal){
         if(newVal==1){
         $("#contractorDiv").show();
         $("#contractor").textbox("enableValidation");
         }else{
         $("#contractorDiv").hide();
         $("#contractor").textbox("clear");
         $("#contractor").textbox("disableValidation");
         $("#contractorId").val('');
         }
         }
         }*/
    });
    /**
     * 是否选择工厂模式切换
     */
    $("#isFactoryModel").combobox({
        onSelect: function (record) {
            var val = record.value;
            if (val == 1) {
                $("#siteNameDiv").hide();
                $("#siteName").textbox("clear");
                $("#siteName").textbox("disableValidation");
                $("#siteIdDiv").show();
                $("#site").textbox("enableValidation");
            } else {
                $("#siteIdDiv").hide();
                $("#siteId").val('');
                $("#site").textbox("clear");
                $("#site").textbox("disableValidation");
                $("#siteNameDiv").show();
                $("#siteName").textbox("enableValidation");
            }
        }
    });

});
/**
 * 定义表单验证
 */
$.extend($.fn.validatebox.defaults.rules, {
    minLength: {
        validator: function (value, param) {
            return value.length >= param[0];
        },
        message: '最小长度'
    },
    intOrFloat: {// 验证整数或小数
        validator: function (value) {
            // alert(/^\d+(\.\d+)?$/i.test(value));
            return /^\d+(\.\d+)?$/i.test(value);
        },
        message: '请输入数字，并确保格式正确'
    },
    int: {
        validator: function (value) {
            return /^([+]?[0-9])|([-]?[0-9])+\d*$/i.test(value);
        },
        message: '请输入整数'
    },
    validSelect: {//验证为空字符串
        validator: function (value) {
            //alert(value!="请选择");
            return value != "请选择" && value != '';
        },
        message: '请选择'
    }

});
/**
 * 查询部门树方法
 */
function queryDepartmentTree() {
    $.ajax({
        url: ROOT_PATH + '/permission/department/getDepartmentTree.shtml',//提交地址
        data: {parentId: 0},//将表单数据序列化
        type: "POST",
        dataType: "json",
        success: function (result) {
            $('#dept').combotree(
                {
                    data: result,
                    loadFilter: function (data) {
                        var newData = new Array();
                        newData.push({id: "", text: '请选择'});
                        newData.push(data[0]);
                        return newData;
                    }
                }
            );
            //事故发生单位
            $("#happenDeptId").combotree({
                data: result,
                loadFilter: function (data) {
                    var newData = new Array();
                    newData.push({id: "", text: '请选择'});
                    newData.push(data[0]);
                    return newData;
                }
            });
            //报告单位
            $("#reportDeptId").combotree({
                data: result,
                loadFilter: function (data) {
                    var newData = new Array();
                    newData.push({id: "", text: '请选择'});
                    newData.push(data[0]);
                    return newData;
                }
            });
            //主管单位
            $("#competentDeptId").combotree({
                data: result,
                loadFilter: function (data) {
                    var newData = new Array();
                    newData.push({id: "", text: '请选择'});
                    newData.push(data[0]);
                    return newData;
                }
            });
        }
    });
}
/**
 * 人员信息选择
 */
var add_userInfo_func = function () {
    WindowManager.openLayer({
        type: 2,
        title: '选择人员信息',
        area: ['1150px', '70%'],
        content: ROOT_PATH + '/permission/user/simpleList.shtml?isMulti=0',
        callBack: function (data) {//窗口关闭后的回调函数
            //$('#listGrid').datagrid("reload");
            if (selectUserId == "" || selectUserId == null) {
                var dutyUserED = datagrid.datagrid('getEditor', {index: editRow, field: 'dutyUserName'});
                var dutyUserIdED = datagrid.datagrid('getEditor', {index: editRow, field: 'dutyUserId'});
                $(dutyUserED.target).textbox("setValue", data[0].realName)
                $(dutyUserIdED.target).textbox("setValue", data[0].id)
            } else {//给正常文本框赋值
                //$("#"+selectUserId+"Id").textbox('setValue',data[0].id);
                $("#" + selectUserId).textbox('setValue', data[0].realName);
                $("#" + selectUserId + "Id").val(data[0].id);
                selectUserId = "";
            }
        }
    });
};
/**
 * 选择人员信息 行编辑使用
 * @param datagridType
 */
function selectUserInfo_datagrid(datagridType) {
    var datagrid = eval("(" + "datagrid" + datagridType + ")");
    var editRow = eval("(" + "editRow" + datagridType + ")");
    WindowManager.openLayer({
        type: 2,
        title: '选择人员信息',
        area: ['1150px', '70%'],
        content: ROOT_PATH + '/permission/user/simpleList.shtml?isMulti=0',
        callBack: function (data) {//窗口关闭后的回调函数
            console.log(data);
            //$('#listGrid').datagrid("reload");
            var userNameED = datagrid.datagrid('getEditor', {index: editRow, field: 'userName'});
            var userIdED = datagrid.datagrid('getEditor', {index: editRow, field: 'userId'});
            $(userNameED.target).textbox("setValue", data[0].realName);
            $(userIdED.target).textbox("setValue", data[0].id);
            /*if(datagridType==1){

             }*/
        }
    });
}
/**
 * 选择责任人 行编辑使用
 * @param datagridType
 */
function selectDutyUserInfo_datagrid(datagridType) {
    var datagrid = eval("(" + "datagrid" + datagridType + ")");
    var editRow = eval("(" + "editRow" + datagridType + ")");
    WindowManager.openLayer({
        type: 2,
        title: '选择人员信息',
        area: ['1150px', '70%'],
        content: ROOT_PATH + '/permission/user/simpleList.shtml?isMulti=0',
        callBack: function (data) {//窗口关闭后的回调函数
            //$('#listGrid').datagrid("reload");
            var userNameED = datagrid.datagrid('getEditor', {index: editRow, field: 'dutyUserName'});
            var userIdED = datagrid.datagrid('getEditor', {index: editRow, field: 'dutyUserId'});
            $(userNameED.target).textbox("setValue", data[0].realName);
            $(userIdED.target).textbox("setValue", data[0].id);
        }
    });
}
/**
 * 选择验证人 行编辑使用
 * @param datagridType
 */
function selectVerifyUserInfo_datagrid(datagridType) {
    var datagrid = eval("(" + "datagrid" + datagridType + ")");
    var editRow = eval("(" + "editRow" + datagridType + ")");
    WindowManager.openLayer({
        type: 2,
        title: '选择人员信息',
        area: ['1150px', '70%'],
        content: ROOT_PATH + '/permission/user/simpleList.shtml?isMulti=0',
        callBack: function (data) {//窗口关闭后的回调函数
            //$('#listGrid').datagrid("reload");
            var userNameED = datagrid.datagrid('getEditor', {index: editRow, field: 'verifyUserName'});
            var userIdED = datagrid.datagrid('getEditor', {index: editRow, field: 'verifyUserId'});
            $(userNameED.target).textbox("setValue", data[0].realName);
            $(userIdED.target).textbox("setValue", data[0].id);
        }
    });
}
/**
 * 选择风险区域的方法
 */
var add_riskRegionInfo_func = function () {
    WindowManager.openLayer({
        type: 2,
        title: '选择风险区域',
        area: ['1150px', '70%'],
        content: ROOT_PATH + '/risk/region/simpleList.shtml',
        callBack: function (data) {//窗口关闭后的回调函数
            $("#" + selectUserId).textbox('setValue', data.name);
            //$("#"+selectUserId+"Id").textbox('setText',data.name);
            $("#" + selectUserId + "Id").val(data.id);
            selectUserId = "";

        }
    });
}
/**
 * 选择作业项目
 */
var add_jobProject_func = function () {
    WindowManager.openLayer({
        type: 2,
        title: '选择项目',
        area: ['800px', '300px'],
        content: ROOT_PATH + '/threeSimultaneities/projectInfo/projectQueryList.shtml',
        callBack: function (data) {
            //alert();
            $("#projectId").val(data[0].id);
            $("#project").textbox("setValue", data[0].name);
            //("#jobProject").textbox("setText",data[0].name);
        }
    });
}
var add_accident_func = function () {
    WindowManager.openLayer({
        type: 2,
        title: '选择项目',
        area: ['1150px', '70%'],
        content: ROOT_PATH + '/accidentEvent/accident/simpleList.shtml',
        callBack: function (data) {
            $("#" + selectUserId).textbox('setValue', data.name);
            //$("#"+selectUserId+"Id").textbox('setText',data.name);
            $("#" + selectUserId + "Id").val(data.id);
            selectUserId = "";
            //事故发生单位
            $("#happenDept").textbox("setValue", data.happenDeptName);
            //事故发生时间
            $("#happenTime").textbox("setValue", data.happenTime);
            //事故级别
            $("#accidentLevelId").textbox("setValue", data.accidentLevelName);
            //事故类别
            $("#accidentTypeId").textbox("setValue", data.accidentTypeName);
            //项目名称
            $("#project").textbox("setValue", data.projectName);
            //
            $("#isFactoryModel").combobox("setValue", data.isFactoryModel);
            //事故发生地点
            if (data.siteName) {
                $("#siteName").textbox("setValue", data.siteName);
            } else {
                $("#site").textbox("setValue", data.siteIdName);
            }
            //具体部位
            $("#specificSite").textbox("setValue", data.specificSite);
            //是否境外事故
            $("#isOverseas").combobox("setValue", data.isOverseas);
            //是否承包商事故
            $("#isContractor").combobox("setValue", data.isContractor);
            if (data.isContractor == 1) {
                $("#contractor").textbox("setValue", data.contractorName);

            }
            //事故经过
            $("#course").textbox("setValue", data.course);
            //事故处理情况
            $("#handleCondition").textbox("setValue", data.handleCondition);


        }
    });
}

/**
 * 查询数据字典列表的方法
 * @param id
 * @param code
 */
function queryDictionaryList(id, code) {
    $.ajax({
        url: ROOT_PATH + '/permission/dictionary/queryDictionaryByDictionaryTypeCode.shtml',//提交地址
        data: {code: code},//将表单数据序列化
        type: "POST",
        dataType: "json",
        success: function (result) {
            $('#' + id).combobox(
                {
                    data: result,
                    valueField: 'id',
                    textField: 'text',
                    loadFilter: function (data) {
                        var newData = new Array();
                        newData.push({id: "", text: '请选择'});
                        for (var i = 0; i < data.length; i++) {
                            newData.push(data[i])
                        }
                        return newData;
                    }
                }
            );

        }
    });
}
/**
 * 设置年度下拉列表
 * @param id
 * @param code
 */
function queryYearthList(id) {
    var date = new Date();
    var year = date.getFullYear();
    var yearthData = new Array();
    yearthData.push({id: "", text: "请选择"});
    for (var i = 0; i < 6; i++) {
        var y = {id: year - i, text: (year - i) + '年'}
        yearthData.push(y);
    }
    $('#' + id).combobox(
        {
            data: yearthData,
            valueField: 'id',
            textField: 'text'
        }
    );
}
/**
 * 选择风险信息弹出框方法
 */
var add_riskLevelInfo_func = function () {
    WindowManager.openLayer({
        type: 2,
        title: '选择风险矩阵信息',
        area: ['60%', '70%'],
        content: ROOT_PATH + '/risk/matrix/toMatrixPage.shtml',
        callBack: function (data) {//窗口关闭后的回调函数
            $("#riskAssessMax").textbox("setValue", data.riskMax);
            $("#riskAssessPeople").textbox("setValue", data.riskPeople);
            $("#riskAssessMoney").textbox("setValue", data.riskMoney);
            $("#riskAssessEnvironment").textbox("setValue", data.riskEnvironment);
            $("#riskAssessPrestige").textbox("setValue", data.riskPrestige);
            $("#riskAssessUserId").textbox("setValue", loginUserId);
            $("#riskAssessUserId").textbox("setText", loginUserName);
        }
    });
};
/**
 * 查询人员类别
 */
function queryPersonalType(datagridType) {
    var datagrid = eval("(" + "datagrid" + datagridType + ")");
    var editRow = eval("(" + "editRow" + datagridType + ")");
    $.ajax({
        url: ROOT_PATH + '/permission/dictionary/queryDictionaryByDictionaryTypeCode.shtml',//提交地址
        data: {code: CONSTANT.DictionaryTypeDefConstants.PERSONAL_TYPE},//将表单数据序列化
        type: "POST",
        dataType: "json",
        success: function (result) {
            var personalTypeIdED = datagrid.datagrid('getEditor', {index: editRow, field: 'personalTypeId'});
            var personalTypeNameED = datagrid.datagrid('getEditor', {index: editRow, field: 'personalTypeName'});
            $(personalTypeIdED.target).combobox(
                {
                    data: result,
                    valueField: 'id',
                    textField: 'text',
                    editable: false,
                    required: true,
                    validType: 'validSelect',
                    width: '100%',
                    // multiple:'true',
                    onSelect: function (r) {
                        $(personalTypeNameED.target).textbox('setValue', r.text);
                    },
                    loadFilter: function (data) {
                        var newData = new Array();
                        newData.push({id: "", text: '请选择'});
                        for (var i = 0; i < data.length; i++) {
                            newData.push(data[i])
                        }
                        return newData;
                    },
                    onLoadSuccess: function () {
                        //设置初始值
                        var val = datagrid.datagrid('getRows')[editRow].personalTypeId;
                        if (val) {
                            $(personalTypeIdED.target).combobox("setValues", val);
                        }


                    }
                }
            );

        }
    });
}
/**
 * 查询文化程度
 */
function queryEducationDegree(datagridType) {
    var datagrid = eval("(" + "datagrid" + datagridType + ")");
    var editRow = eval("(" + "editRow" + datagridType + ")");
    $.ajax({
        url: ROOT_PATH + '/permission/dictionary/queryDictionaryByDictionaryTypeCode.shtml',//提交地址
        data: {code: CONSTANT.DictionaryTypeDefConstants.DEGREE_EDUCATION},//将表单数据序列化
        type: "POST",
        dataType: "json",
        success: function (result) {
            var educationIdED = datagrid.datagrid('getEditor', {index: editRow, field: 'educationId'});
            var educationNameED = datagrid.datagrid('getEditor', {index: editRow, field: 'educationName'});
            $(educationIdED.target).combobox(
                {
                    data: result,
                    valueField: 'id',
                    textField: 'text',
                    editable: false,
                    required: true,
                    validType: 'validSelect',
                    width: '100%',
                    // multiple:'true',
                    onSelect: function (r) {
                        $(educationNameED.target).textbox('setValue', r.text);
                    },
                    loadFilter: function (data) {
                        var newData = new Array();
                        newData.push({id: "", text: '请选择'});
                        for (var i = 0; i < data.length; i++) {
                            newData.push(data[i])
                        }
                        return newData;
                    },
                    onLoadSuccess: function () {
                        //设置初始值
                        var val = datagrid.datagrid('getRows')[editRow].educationId;
                        if (val) {
                            $(educationIdED.target).combobox("setValues", val);
                        }


                    }
                }
            );
        }
    });
}
/**
 * 查询直接伤害下拉列表
 */
function queryDirectDamage(datagridType) {
    var datagrid = eval("(" + "datagrid" + datagridType + ")");
    var editRow = eval("(" + "editRow" + datagridType + ")");
    $.ajax({
        url: ROOT_PATH + '/permission/dictionary/queryDictionaryByDictionaryTypeCode.shtml',//提交地址
        data: {code: CONSTANT.DictionaryTypeDefConstants.DIRECT_DAMAGE_REASON},//将表单数据序列化
        type: "POST",
        dataType: "json",
        success: function (result) {
            var directDamageIdED = datagrid.datagrid('getEditor', {index: editRow, field: 'directDamageReasonId'});
            var directDamageNameED = datagrid.datagrid('getEditor', {index: editRow, field: 'directDamageReasonName'});
            $(directDamageIdED.target).combobox(
                {
                    data: result,
                    valueField: 'id',
                    textField: 'text',
                    editable: false,
                    required: true,
                    validType: 'validSelect',
                    width: '100%',
                    // multiple:'true',
                    onSelect: function (r) {
                        $(directDamageNameED.target).textbox('setValue', r.text);
                    },
                    loadFilter: function (data) {
                        var newData = new Array();
                        newData.push({id: "", text: '请选择'});
                        for (var i = 0; i < data.length; i++) {
                            newData.push(data[i])
                        }
                        return newData;
                    },
                    onLoadSuccess: function () {
                        //设置初始值
                        var val = datagrid.datagrid('getRows')[editRow].directDamageReasonId;
                        if (val) {
                            $(directDamageIdED.target).combobox("setValues", val);
                        }
                    }
                }
            );
        }
    });
}
/**
 * 查询伤害部位下拉列表
 */
function queryDamagePart(datagridType) {
    var datagrid = eval("(" + "datagrid" + datagridType + ")");
    var editRow = eval("(" + "editRow" + datagridType + ")");
    $.ajax({
        url: ROOT_PATH + '/permission/dictionary/queryDictionaryByDictionaryTypeCode.shtml',//提交地址
        data: {code: CONSTANT.DictionaryTypeDefConstants.DAMAGE_PART},//将表单数据序列化
        type: "POST",
        dataType: "json",
        success: function (result) {
            var damagePartIdED = datagrid.datagrid('getEditor', {index: editRow, field: 'damagePartId'});
            var damagePartNameED = datagrid.datagrid('getEditor', {index: editRow, field: 'damagePartName'});
            $(damagePartIdED.target).combobox(
                {
                    data: result,
                    valueField: 'id',
                    textField: 'text',
                    editable: false,
                    required: true,
                    validType: 'validSelect',
                    width: '100%',
                    // multiple:'true',
                    onSelect: function (r) {
                        $(damagePartNameED.target).textbox('setValue', r.text);
                    },
                    loadFilter: function (data) {
                        var newData = new Array();
                        newData.push({id: "", text: '请选择'});
                        for (var i = 0; i < data.length; i++) {
                            newData.push(data[i])
                        }
                        return newData;
                    },
                    onLoadSuccess: function () {
                        //设置初始值
                        var val = datagrid.datagrid('getRows')[editRow].damagePartId;
                        if (val) {
                            $(damagePartIdED.target).combobox("setValues", val);
                        }


                    }
                }
            );
        }
    });
}
/**
 * 查询严重程度下拉列表
 */
function querySeverity(datagridType) {
    var datagrid = eval("(" + "datagrid" + datagridType + ")");
    var editRow = eval("(" + "editRow" + datagridType + ")");
    $.ajax({
        url: ROOT_PATH + '/permission/dictionary/queryDictionaryByDictionaryTypeCode.shtml',//提交地址
        data: {code: CONSTANT.DictionaryTypeDefConstants.SEVERITY},//将表单数据序列化
        type: "POST",
        dataType: "json",
        success: function (result) {
            var severityIdED = datagrid.datagrid('getEditor', {index: editRow, field: 'severityId'});
            var severityNameED = datagrid.datagrid('getEditor', {index: editRow, field: 'severityName'});
            var severityLevelED = datagrid.datagrid('getEditor', {index: editRow, field: 'severityLevel'});
            $(severityIdED.target).combobox(
                {
                    data: result,
                    valueField: 'id',
                    textField: 'text',
                    editable: false,
                    required: true,
                    validType: 'validSelect',
                    width: '100%',
                    // multiple:'true',
                    onSelect: function (r) {
                        $(severityLevelED.target).textbox('setValue', r.data1);
                        $(severityNameED.target).textbox('setValue', r.text);
                    },
                    loadFilter: function (data) {
                        var newData = new Array();
                        newData.push({id: "", text: '请选择'});
                        for (var i = 0; i < data.length; i++) {
                            newData.push(data[i])
                        }
                        return newData;
                    },
                    onLoadSuccess: function () {
                        //设置初始值
                        var val = datagrid.datagrid('getRows')[editRow].severityId;
                        if (val) {
                            $(severityIdED.target).combobox("setValues", val);
                        }


                    }
                }
            );
        }
    });
}
/**
 * 查询责任类型下拉列表
 */
function queryDutyType(datagridType) {
    var datagrid = eval("(" + "datagrid" + datagridType + ")");
    var editRow = eval("(" + "editRow" + datagridType + ")");
    $.ajax({
        url: ROOT_PATH + '/permission/dictionary/queryDictionaryByDictionaryTypeCode.shtml',//提交地址
        data: {code: CONSTANT.DictionaryTypeDefConstants.DUTY_TYPE},//将表单数据序列化
        type: "POST",
        dataType: "json",
        success: function (result) {
            var dutyTypeIdED = datagrid.datagrid('getEditor', {index: editRow, field: 'dutyTypeId'});
            var dutyTypeNameED = datagrid.datagrid('getEditor', {index: editRow, field: 'dutyTypeName'});
            $(dutyTypeIdED.target).combobox(
                {
                    data: result,
                    valueField: 'id',
                    textField: 'text',
                    editable: false,
                    required: true,
                    validType: 'validSelect',
                    width: '100%',
                    // multiple:'true',
                    onSelect: function (r) {
                        $(dutyTypeNameED.target).textbox('setValue', r.text);
                    },
                    loadFilter: function (data) {
                        var newData = new Array();
                        newData.push({id: "", text: '请选择'});
                        for (var i = 0; i < data.length; i++) {
                            newData.push(data[i])
                        }
                        return newData;
                    },
                    onLoadSuccess: function () {
                        //设置初始值
                        var val = datagrid.datagrid('getRows')[editRow].dutyTypeId;
                        if (val) {
                            $(dutyTypeIdED.target).combobox("setValues", val);
                        }


                    }
                }
            );
        }
    });
}
/**
 * 查询直接原因类型
 * @param id
 * @param code
 */
function queryDirectReasonTypeList(id, code) {
    $.ajax({
        url: ROOT_PATH + '/permission/dictionary/queryDictionaryByDictionaryTypeCode.shtml',//提交地址
        data: {code: code},//将表单数据序列化
        type: "POST",
        dataType: "json",
        success: function (result) {
            $('#' + id).combobox(
                {
                    data: result,
                    valueField: 'id',
                    textField: 'text',
                    loadFilter: function (data) {
                        var newData = new Array();
                        newData.push({id: "", text: '请选择'});
                        for (var i = 0; i < data.length; i++) {
                            newData.push(data[i])
                        }
                        return newData;
                    },
                    /*   onLoadSuccess:function(){
                     //设置初始值
                     var val = datagrid.datagrid('getRows')[editRow].dutyTypeId;
                     if(val){
                     $(dutyTypeIdED.target).combobox("setValues",val);
                     }
                     },*/
                    onSelect: function (r) {
                        if (r.data1 === "1") {
                            $("#unsafeStateId").combobox("enable");
                            $("#unsafeActId").combobox("disable");
                        } else if (r.data1 === "0") {
                            $("#unsafeActId").combobox("enable");
                            $("#unsafeStateId").combobox("disable");
                        } else {
                            $("#unsafeActId").combobox("disable");
                            $("#unsafeStateId").combobox("disable");
                        }
                        //$(dutyTypeNameED.target).textbox('setValue',r.text);
                    },
                }
            );

        }
    });
}

/*===================================行编辑方法s===========================================*/
/*==========人员伤亡信息方法=========================*/
/**
 * 添加编辑行
 */
function appendTableRow1() {//添加列表的操作按钮添加，修改，删除等
    //添加时先判断是否有开启编辑的行，如果有则把开户编辑的那行结束编辑
    if (editRow1 != undefined) {
        datagrid1.datagrid("endEdit", editRow1);
    }
    //添加时如果没有正在编辑的行，则在datagrid的第一行插入一行
    if (editRow1 == undefined) {
        datagrid1.datagrid("insertRow", {
            index: 0, // index start with 0
            row: {}
        });
        //将新插入的那一行开启编辑状态
        datagrid1.datagrid("beginEdit", 0);
        //给当前编辑的行赋值
        editRow1 = 0;
    }
    //加载人员类别下拉框
    queryPersonalType("1");
    //加载文化程度
    queryEducationDegree("1");
    //直接伤害原因
    queryDirectDamage("1");
    //查询伤害部位
    queryDamagePart("1");
    //严重程度下拉列表
    querySeverity("1");
}

/**
 * 删除行
 */
function deleteTableRow1() {
    //删除时先获取选择行
    var rows = datagrid1.datagrid("getSelections");
    //选择要删除的行
    if (rows.length > 0) {
        var index = layer.confirm("确定要删除吗？", {btn: ["确定", "取消"]}, function () {
            var ids = [];
            /*for (var i = 0; i < rows.length; i++) {
             ids.push(rows[i].ID);
             }*/
            var row = datagrid1.datagrid("getSelected");
            var selectedIndex = datagrid1.datagrid('getRowIndex', row);
            datagrid1.datagrid('deleteRow', selectedIndex);
            editRow1 = undefined;
            //将选择到的行存入数组并用,分隔转换成字符串，
            //本例只是前台操作没有与数据库进行交互所以此处只是弹出要传入后台的id
            //alert(ids.join(','));
            layer.close(index);
        });
    } else {
        layer.alert("请选择删除行！");
    }
}

/**
 * 保存行数据
 */
function saveTableRow1() {
    //保存时结束当前编辑的行，自动触发onAfterEdit事件如果要与后台交互可将数据通过Ajax提交后台
    datagrid1.datagrid("endEdit", editRow1);
}

/**
 * 编辑行数据
 */
function editTableRow1() {
    //修改时要获取选择到的行
    var rows = datagrid1.datagrid("getSelections");
    //如果只选择了一行则可以进行修改，否则不操作
    if (rows.length == 1) {
        //修改之前先关闭已经开启的编辑行，当调用endEdit该方法时会触发onAfterEdit事件
        if (editRow1 != undefined) {
            datagrid1.datagrid("endEdit", editRow1);
        }
        //当无编辑行时
        if (editRow1 == undefined) {
            //获取到当前选择行的下标
            var index = datagrid1.datagrid("getRowIndex", rows[0]);
            //开启编辑
            datagrid1.datagrid("beginEdit", index);
            //把当前开启编辑的行赋值给全局变量editRow
            editRow1 = index;
            //当开启了当前选择行的编辑状态之后，
            //应该取消当前列表的所有选择行，要不然双击之后无法再选择其他行进行编辑
            datagrid1.datagrid("unselectAll");
        }
    }
    //加载人员类别下拉框
    queryPersonalType("1");
    //加载文化程度
    queryEducationDegree("1");
    //直接伤害原因
    queryDirectDamage("1");
    //查询伤害部位
    queryDamagePart("1");
    //严重程度下拉列表
    querySeverity("1");
}
/**
 * 取消编辑行
 */
function rejectTableRow1() {
    var index = layer.confirm("确定撤销将删除所有的编辑数据！", {btn: ['确定', '取消']}, function () {
        //取消当前编辑行把当前编辑行罢undefined回滚改变的数据,取消选择的行
        editRow1 = undefined;
        datagrid1.datagrid("rejectChanges");
        datagrid1.datagrid("unselectAll");
        layer.close(index);
    });

}
/*==========负责人处理意见=========================*/
/**
 * 添加编辑行
 */
function appendTableRow2() {//添加列表的操作按钮添加，修改，删除等
    //添加时先判断是否有开启编辑的行，如果有则把开户编辑的那行结束编辑
    if (editRow2 != undefined) {
        datagrid2.datagrid("endEdit", editRow2);
    }
    //添加时如果没有正在编辑的行，则在datagrid的第一行插入一行
    if (editRow2 == undefined) {
        datagrid2.datagrid("insertRow", {
            index: 0, // index start with 0
            row: {}
        });
        //将新插入的那一行开启编辑状态
        datagrid2.datagrid("beginEdit", 0);
        //给当前编辑的行赋值
        editRow2 = 0;
    }
    //加载责任类型下拉列表
    queryDutyType("2");
    //加载人员类别下拉框
    queryPersonalType("2");
}

/**
 * 删除行
 */
function deleteTableRow2() {
    //删除时先获取选择行
    var rows = datagrid2.datagrid("getSelections");
    //选择要删除的行
    if (rows.length > 0) {
        var index = layer.confirm("确定要删除吗？", {btn: ["确定", "取消"]}, function () {
            var ids = [];
            /*for (var i = 0; i < rows.length; i++) {
             ids.push(rows[i].ID);
             }*/
            var row = datagrid2.datagrid("getSelected");
            var selectedIndex = datagrid2.datagrid('getRowIndex', row);
            datagrid2.datagrid('deleteRow', selectedIndex);
            editRow2 = undefined;
            //将选择到的行存入数组并用,分隔转换成字符串，
            //本例只是前台操作没有与数据库进行交互所以此处只是弹出要传入后台的id
            //alert(ids.join(','));
            layer.close(index);
        });
    } else {
        layer.alert("请选择删除行！");
    }
}

/**
 * 保存行数据
 */
function saveTableRow2() {
    //保存时结束当前编辑的行，自动触发onAfterEdit事件如果要与后台交互可将数据通过Ajax提交后台
    datagrid2.datagrid("endEdit", editRow2);
}

/**
 * 编辑行数据
 */
function editTableRow2() {
    //修改时要获取选择到的行
    var rows = datagrid2.datagrid("getSelections");
    //如果只选择了一行则可以进行修改，否则不操作
    if (rows.length == 1) {
        //修改之前先关闭已经开启的编辑行，当调用endEdit该方法时会触发onAfterEdit事件
        if (editRow2 != undefined) {
            datagrid2.datagrid("endEdit", editRow2);
        }
        //当无编辑行时
        if (editRow2 == undefined) {
            //获取到当前选择行的下标
            var index = datagrid2.datagrid("getRowIndex", rows[0]);
            //开启编辑
            datagrid2.datagrid("beginEdit", index);
            //把当前开启编辑的行赋值给全局变量editRow
            editRow2 = index;
            //当开启了当前选择行的编辑状态之后，
            //应该取消当前列表的所有选择行，要不然双击之后无法再选择其他行进行编辑
            datagrid2.datagrid("unselectAll");
        }
    }
    //加载责任类型下拉列表
    queryDutyType("2");
    //加载人员类别下拉框
    queryPersonalType("2");

}
/**
 * 取消编辑行
 */
function rejectTableRow2() {
    var index = layer.confirm("确定撤销将删除所有的编辑数据！", {btn: ['确定', '取消']}, function () {
        //取消当前编辑行把当前编辑行罢undefined回滚改变的数据,取消选择的行
        editRow2 = undefined;
        datagrid2.datagrid("rejectChanges");
        datagrid2.datagrid("unselectAll");
        layer.close(index);
    });

}
/*====================防范措施================================*/
/**
 * 添加编辑行
 */
function appendTableRow3() {//添加列表的操作按钮添加，修改，删除等
    //添加时先判断是否有开启编辑的行，如果有则把开户编辑的那行结束编辑
    if (editRow3 != undefined) {
        datagrid3.datagrid("endEdit", editRow3);
    }
    //添加时如果没有正在编辑的行，则在datagrid的第一行插入一行
    if (editRow3 == undefined) {
        datagrid3.datagrid("insertRow", {
            index: 0, // index start with 0
            row: {}
        });
        //将新插入的那一行开启编辑状态
        datagrid3.datagrid("beginEdit", 0);
        //给当前编辑的行赋值
        editRow3 = 0;
    }
}

/**
 * 删除行
 */
function deleteTableRow3() {
    //删除时先获取选择行
    var rows = datagrid3.datagrid("getSelections");
    //选择要删除的行
    if (rows.length > 0) {
        var index = layer.confirm("确定要删除吗？", {btn: ["确定", "取消"]}, function () {
            var ids = [];
            /*for (var i = 0; i < rows.length; i++) {
             ids.push(rows[i].ID);
             }*/
            var row = datagrid3.datagrid("getSelected");
            var selectedIndex = datagrid3.datagrid('getRowIndex', row);
            datagrid3.datagrid('deleteRow', selectedIndex);
            editRow3 = undefined;
            //将选择到的行存入数组并用,分隔转换成字符串，
            //本例只是前台操作没有与数据库进行交互所以此处只是弹出要传入后台的id
            //alert(ids.join(','));
            layer.close(index);
        });
    } else {
        layer.alert("请选择删除行！");
    }
}

/**
 * 保存行数据
 */
function saveTableRow3() {
    //保存时结束当前编辑的行，自动触发onAfterEdit事件如果要与后台交互可将数据通过Ajax提交后台
    datagrid3.datagrid("endEdit", editRow3);
}

/**
 * 编辑行数据
 */
function editTableRow3() {
    //修改时要获取选择到的行
    var rows = datagrid3.datagrid("getSelections");
    //如果只选择了一行则可以进行修改，否则不操作
    if (rows.length == 1) {
        //修改之前先关闭已经开启的编辑行，当调用endEdit该方法时会触发onAfterEdit事件
        if (editRow3 != undefined) {
            datagrid3.datagrid("endEdit", editRow3);
        }
        //当无编辑行时
        if (editRow3 == undefined) {
            //获取到当前选择行的下标
            var index = datagrid3.datagrid("getRowIndex", rows[0]);
            //开启编辑
            datagrid3.datagrid("beginEdit", index);
            //把当前开启编辑的行赋值给全局变量editRow
            editRow3 = index;
            //当开启了当前选择行的编辑状态之后，
            //应该取消当前列表的所有选择行，要不然双击之后无法再选择其他行进行编辑
            datagrid3.datagrid("unselectAll");
        }
    }
    //加载风险类型下拉列表
    //queryRiskType();

}
/**
 * 取消编辑行
 */
function rejectTableRow() {
    var index = layer.confirm("确定撤销将删除所有的编辑数据！", {btn: ['确定', '取消']}, function () {
        //取消当前编辑行把当前编辑行罢undefined回滚改变的数据,取消选择的行
        editRow3 = undefined;
        datagrid3.datagrid("rejectChanges");
        datagrid3.datagrid("unselectAll");
        layer.close(index);
    });

}


/**
 * 添加编辑行
 */
function appendTableRow(datagridId) {//添加列表的操作按钮添加，修改，删除等
    var datagrid = $("#" + datagridId);
    //添加时先判断是否有开启编辑的行，如果有则把开户编辑的那行结束编辑
    if (editRow != undefined) {
        datagrid.datagrid("endEdit", editRow);
    }
    //添加时如果没有正在编辑的行，则在datagrid的第一行插入一行
    if (editRow == undefined) {
        datagrid.datagrid("insertRow", {
            index: 0, // index start with 0
            row: {}
        });
        //将新插入的那一行开启编辑状态
        datagrid.datagrid("beginEdit", 0);
        //给当前编辑的行赋值
        editRow = 0;
    }
}

/**
 * 删除行
 */
function deleteTableRow(datagridId) {
    var datagrid = $("#" + datagridId);
    //删除时先获取选择行
    var rows = datagrid.datagrid("getSelections");
    //选择要删除的行
    if (rows.length > 0) {
        var index = layer.confirm("确定要删除吗？", {btn: ["确定", "取消"]}, function () {
            var ids = [];
            /*for (var i = 0; i < rows.length; i++) {
             ids.push(rows[i].ID);
             }*/
            var row = datagrid.datagrid("getSelected");
            var selectedIndex = datagrid.datagrid('getRowIndex', row);
            datagrid.datagrid('deleteRow', selectedIndex);
            editRow = undefined;
            //将选择到的行存入数组并用,分隔转换成字符串，
            //本例只是前台操作没有与数据库进行交互所以此处只是弹出要传入后台的id
            //alert(ids.join(','));
            layer.close(index);
        });
    } else {
        layer.alert("请选择删除行！");
    }
}

/**
 * 保存行数据
 */
function saveTableRow(datagridId) {
    var datagrid = $("#" + datagridId);
    //保存时结束当前编辑的行，自动触发onAfterEdit事件如果要与后台交互可将数据通过Ajax提交后台
    datagrid.datagrid("endEdit", editRow);
}

/**
 * 编辑行数据
 */
function editTableRow(datagridId) {
    var datagrid = $("#" + datagridId);
    //修改时要获取选择到的行
    var rows = datagrid.datagrid("getSelections");
    //如果只选择了一行则可以进行修改，否则不操作
    if (rows.length == 1) {
        //修改之前先关闭已经开启的编辑行，当调用endEdit该方法时会触发onAfterEdit事件
        if (editRow != undefined) {
            datagrid.datagrid("endEdit", editRow);
        }
        //当无编辑行时
        if (editRow == undefined) {
            //获取到当前选择行的下标
            var index = datagrid.datagrid("getRowIndex", rows[0]);
            //开启编辑
            datagrid.datagrid("beginEdit", index);
            //把当前开启编辑的行赋值给全局变量editRow
            editRow = index;
            //当开启了当前选择行的编辑状态之后，
            //应该取消当前列表的所有选择行，要不然双击之后无法再选择其他行进行编辑
            datagrid.datagrid("unselectAll");
        }
    }
    //加载风险类型下拉列表
    //queryRiskType();

}
/**
 * 取消编辑行
 */
function rejectTableRow(datagridId) {
    var datagrid = $("#" + datagridId);
    var index = layer.confirm("确定撤销将删除所有的编辑数据！", {btn: ['确定', '取消']}, function () {
        //取消当前编辑行把当前编辑行罢undefined回滚改变的数据,取消选择的行
        editRow = undefined;
        datagrid.datagrid("rejectChanges");
        datagrid.datagrid("unselectAll");
        layer.close(index);
    });

}
/**
 * 提交表格行编辑数据
 */
function getDetailData1() {
    //var datagrid = $("#"+datagridId);
    //保存表格编辑数据
    saveTableRow1();
    //获取编辑表格数据
    var rows = datagrid1.datagrid("getRows");
    return JSON.stringify(rows);
}
function getDetailData2() {
    //var datagrid = $("#"+datagridId);
    //保存表格编辑数据
    saveTableRow2();
    //获取编辑表格数据
    var rows = datagrid2.datagrid("getRows");
    return JSON.stringify(rows);
}
function getDetailData3() {
    //var datagrid = $("#"+datagridId);
    //保存表格编辑数据
    saveTableRow3();
    //获取编辑表格数据
    var rows = datagrid3.datagrid("getRows");
    return JSON.stringify(rows);
}




